<template>
  <view class="my-userinfo-container">
    <!-- 头像昵称区域 -->
    <view class="top-box">
      <view class="animate__animated animate__lightSpeedInLeft">
      <image :src="userimgname.avatar===''?avaterimg:userimgname.avatar" class="avatar"></image>
      <view class="nickname">{{userimgname.nickname===''?nickname:userimgname.nickname}}</view>
      </view>
    </view>

    <!-- 面板的列表区域 -->
    <view class="panel-list  animate__animated animate__fadeInLeftBig">
      <my-audio></my-audio>
      <!-- 第一个面板 -->
      <view class="panel">
        <!-- panel 的主体区域 -->
        <view class="panel-body">
          <!-- panel 的 item 项 -->
          <view class="panel-item">
            <text>{{cart.length}}</text>
            <text>壁纸集总数</text>
          </view>
          <view class="panel-item">
            <text>∞</text>
            <text>未知领域</text>
          </view>
          <view class="panel-item">
            <text>∞</text>
            <text>未知领域</text>
          </view>
          <view class="panel-item">
            <text>∞</text>
            <text>未知领域</text>
          </view>
        </view>
      </view>

      <!-- 第二个面板 -->
      <!-- 第二个面板 -->
      <view class="panel">
        <!-- 面板的标题 -->
        <view class="panel-title">功能选项</view>
        <!-- 面板的主体 -->
        <view class="panel-body">
          <!-- 面板主体中的 item 项 -->
          <view class="panel-item">
            <image :src="avaterimg" class="icon" style="width: 44px;height: 44px;border-radius: 12px;"></image>
            <text>组件开发中...</text>
          </view>
          <view class="panel-item">
            <image :src="avaterimg" class="icon" style="width: 44px;height: 44px;border-radius: 12px;"></image>
            <text>组件开发中...</text>
          </view>
          <view class="panel-item">
            <image :src="avaterimg" class="icon" style="width: 44px;height: 44px;border-radius: 12px;"></image>
            <text>组件开发中...</text>
          </view>
          <view class="panel-item">
            <image :src="avaterimg" class="icon" style="width: 44px;height: 44px;border-radius: 12px;"></image>
            <text>组件开发中...</text>
          </view>
        </view>
      </view>
      <!-- 第三个面板 -->
      <view class="panel">
        <view class="panel-list-item" @click="navigatorcart">
          <text>备份地址</text>
          <uni-icons type="arrowright" size="15"></uni-icons>
        </view>
        <button class="panel-list-item" open-type="feedback">
          联系客服
          <uni-icons type="arrowright" size="15"></uni-icons>
        </button>
        <view class="panel-list-item" @click="logout">
          <text>退出登录</text>
          <uni-icons type="arrowright" size="15"></uni-icons>
        </view>
      </view>
      <!-- 广告 -->
      <ad unit-id="adunit-b2633f17e1ca7516" ad-type="video" ad-theme="white"></ad>
    </view>
  </view>
</template>

<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    name: "my-userinfo",
    data() {
      return {
        avaterimg: 'https://pic.imgdb.cn/item/63de22654757feff33171a00.png',
        nickname: '璐瑶成鲲',
      };
    },
    computed: {
      ...mapState('m_user', ['userimgname']),
      ...mapState('m_cart', ['cart'])
    },
    methods: {
      ...mapMutations('m_user', ['updataUserInfo', 'updataToken', 'updateAddress']),
      async logout() {
        const [err, succ] = await uni.showModal({
          title: '温馨提示',
          content: '亲！确定要退出吗？'
        }).catch(err => err)
        if (succ && succ.confirm) {
          this.updataToken('')
          this.updataUserInfo({})
          this.updateAddress({})
        }
      },
      navigatorcart() {
        uni.switchTab({
          url: '/pages/cart/cart'
        })
      },

    }
  }
</script>

<style lang="less">
  .my-userinfo-container {
    height: 100%;
    // 为整个组件的结构添加浅灰色的背景
    // background-color: #f4f4f4;

    .top-box {
      height: 400rpx;
      background-image: url(https://pic.imgdb.cn/item/63d4f782face21e9ef155ff2.jpg);
      background-position: center;
      background-size: cover;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .avatar {
        display: block;
        width: 90px;
        height: 90px;
        border-radius: 45px;
        border: 2px solid white;
        box-shadow: 0 1px 5px black;
      }

      .nickname {
        font-family: "华文楷体";
        color: red;
        font-weight: bold;
        font-size: 24px;
        margin-top: 10px;
        text-align: center;
      }
    }

    .panel-list {
      padding: 0 10px;
      position: relative;
      top: -28px;

      .panel {
        background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
        border-radius: 12px;
        margin-bottom: 8px;

        .panel-list-item {
          height: 45px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-size: 15px;
          padding: 0 10px;
          background-image: linear-gradient(120deg, #84fab0 0%, #8fd3f4 100%);
          border-radius: 12px;

          button {
            border: 0;
            border-radius: 0;
            padding: 0;
            margin: 0;
          }

          button::after {
            border: none;
            border-radius: 0;
          }
        }

        .panel-title {
          line-height: 45px;
          padding-left: 10px;
          font-size: 15px;
          border-bottom: 1px solid #f4f4f4;
        }

        .panel-body {
          display: flex;
          justify-content: space-around;

          .panel-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-around;
            font-size: 13px;
            padding: 10px 0;

          }
        }
      }
    }
  }
</style>
